import unittest
from pyurl import File, URL
from pyurl.connection import Connection
from file_test_cases import *
from folder_test_cases import *

def suite():
    local_path = "pyurl_test_data/test_folder"
    local_file = "file:pyurl_test_data/test_folder"
    local_zip = "zip:file:pyurl_test_data/test_archive.zip!/"
    local_tar = "tar:file:pyurl_test_data/test_archive.tar.gz!/"
    http_file = "http://files.dennis-kempin.de/pyurl_test_data/test_folder"
    http_zip = "zip:http://files.dennis-kempin.de/pyurl_test_data/test_archive.zip!/"
    
    import os.path
    if os.path.exists("sftp_connection"):
        sftp_base = open("sftp_connection", "r").read().strip()
        sftp_file = sftp_base+"/pyurl_test_dir"
        sftp_zip = "zip:"+sftp_base+"/pyurl_test_archive.zip!/"        
    else:
        sftp_file = None
        sftp_zip = None
        
    read_tests = [ local_path, local_file, local_zip, local_tar, 
                  http_file, http_zip, sftp_file, sftp_zip ]
    
    write_tests = [ local_path, local_file, sftp_file ]
    
    iter_folder_tests = [ local_path, local_file, http_file ]
    
    suite = unittest.TestSuite()
    suite.addTest(unittest.TestLoader().loadTestsFromTestCase(BasicFileTests))
    suite.addTest(load_tests(read_tests, ReadConnectionTests))
    suite.addTest(load_tests(write_tests, WriteConnectionTests))
    suite.addTest(load_tests(iter_folder_tests, IterFolderTests))
    
    return suite


def load_tests(parameter_list, clazz):
    suite = unittest.TestSuite()
    for parameter in parameter_list:
        if parameter:
            new_type = type(clazz.__name__+"("+parameter+")", (clazz,), {"test_root": parameter})
            new_suite = unittest.TestLoader().loadTestsFromTestCase(new_type)
            suite.addTest(new_suite)
    return suite
